package com.qk.controller;

import com.qk.anno.Log;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    //活动列表查询
    @GetMapping
    public Result list(ActivityDto activityDto){
        log.info("查询活动列表:{}",activityDto);
        PageResult<Activity> pageResult=activityService.list(activityDto);
        return Result.success(pageResult);
    }
    //根据ID删除
    @Log
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除用户:{}",id);
        activityService.deleteById(id);
        return Result.success();
    }
    //添加活动
    @Log
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加活动:{}",activity);
        activityService.add(activity);
        return Result.success();
    }
    //根据ID查询
    @GetMapping("/{id}")
    public Result getByID(@PathVariable Integer id){
        log.info("根据ID查询:{}",id);
        Activity activity = activityService.getByID(id);
        return Result.success(activity);
    }
    //修改活动
    @Log
    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("修改活动:{}",activity);
        activityService.upDate(activity);
        return Result.success();
    }
    //查询指定类型的活动
    @GetMapping("/type/{type}")
    public Result typeList(@PathVariable Integer type){
        log.info("查询指定类型的活动:{}",type);
        List<Activity> activityList = activityService.typeList(type);
        return Result.success(activityList);
    }
}
